<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">
        <link rel="icon" href="../../favicon.ico">
        <title><?php echo $OJ_NAME?></title>
        <?php include("template/bs3/css.php");?>
        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
        <!--[if lt IE 9]>
        <script src="http://cdn.bootcss.com/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
        <link rel="stylesheet" href="../../common-static/problem-statement.css">
        <script src="../../common-static/jquery.min.js"></script>
    </head>
    <body>
    <script type="text/x-mathjax-config">
        // MathJax配置,skipTags排除的标签
        MathJax.Hub.Config({
            showProcessingMessages: false,
            messageStyle: "none",
            extensions: ["tex2jax.js"],
            jax: ["input/TeX", "output/HTML-CSS"],
            tex2jax: {
                inlineMath:  [ ["$", "$"] ],
                displayMath: [ ["$$","$$"] ],
                skipTags: ['script', 'noscript', 'style', 'textarea', 'pre','code','a'],
                ignoreClass:"comment-content"
            },
            "HTML-CSS": {
                availableFonts: ["TeX","STIX"],
                showMathMenu: false
            }
        });
        MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
    </script>
    <script src="https://cdn.bootcss.com/mathjax/2.7.3/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <script type="text/javascript" async
            src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
    </script>
    <div class="container">
        <!--导航条-->
        <?php include("template/bs3/nav.php");?>
        <!--题目详细信息-->
        <div class="jumbotron col-md-9">
            <div style="padding-right: 1rem; min-height:45rem;">
                <?php
                // 题目标题
                echo "<center><h2>".SysConfig::$PID_PREFIX.$id.": ".$row['title']."</h2></center>";
                // 题目描述
                echo "<h3>$MSG_Description</h3><div class=content>".$row['description']."</div>";
                // 输入
                echo "<h3>$MSG_Input</h3><div class=content>".$row['input']."</div>";
                // 输出
                echo "<h3>$MSG_Output</h3><div class=content>".$row['output']."</div>";

                // 样例输入
                $sinput=str_replace("<","&lt;",$row['sample_input']);
                $sinput=str_replace(">","&gt;",$sinput);
                $sinput=rtrim($sinput);
                if(strlen($sinput)) {
                    echo "<h3>样例输入<button class='samplebtn' id='sampleinput_btn'>点此复制</button></h3>";
                    echo "<pre id='sampleinput_data' class='content sampledata'>".($sinput)."</pre>";
                }

                // 样例输出
                $soutput=str_replace("<","&lt;",$row['sample_output']);
                $soutput=str_replace(">","&gt;",$soutput);
                $soutput=rtrim($soutput);
                if(strlen($soutput)){
                    echo "<h3>样例输出<button class='samplebtn' id='sampleoutput_btn'>点此复制</button></h3>";
                    echo "<pre id='sampleoutput_data' class='content sampledata'>".($soutput)."</pre>";
                }

                // 提示信息
                echo "<h3>$MSG_HINT</h3>";
                if (strlen($row['hint']) > 0 ) {
                    echo "<div class=content>".$row['hint']."</div>";
                }
                echo "<h3>来源</h3>";
                if (strlen($row['fromoj']) > 0 ) {
                    echo "<div class=content>".$row['fromoj']."</div>";
                }
                ?>
            </div>
        </div>

        <!--题目信息侧边栏-->
        <div class="jumbotron col-md-3">
            <h5 class="zz_side_title">题目信息</h5>
            <ul class="zz_side_bar">
                <?php
                // 提交和通过次数统计
                echo "<li class='zz_first_side_item'>提交: ".$row['submit'];
                echo "<span class='zz_first_side_item'>正确: ".$row['accepted']."<span></li>";

                // 内存和时间限制
                echo "<li class='zz_side_item'>时间限制: ".$row['time_limit']." 秒</li>";
                echo "<li class='zz_side_item'>内存限制: ".$row['memory_limit']." MB</li>";
                echo "<li class='zz_side_item'>难度等级: ".$row['level']." 级</li>";
                echo "<li class='zz_side_item'>创建人: ".$row['creater_id']."</li>";
                ?>
                <li class="zz_side_item" >
                    <a href='submitpage.php?id=<?php echo $id ?>'>
                        <button class="btn btn-primary">提交</button>
                    </a>
                    <a class="zz_side_item" href='problemstatus.php?id=<?php echo $row['problem_id']?>'>
                        <button class="btn btn-primary">统计</button>
                    </a>
                </li>
            </ul>
        </div>
        <!--题目管理侧边栏-->
        <?php
        $allowAccess = isset($_SESSION['administrator']);
        $allowAccess |= isset($_SESSION['problem_editor']) && (strtolower($row['creater_id']) == strtolower($_SESSION['user_id']));
        if( $allowAccess ){
            require_once("include/set_get_key.php");
            //$statusListUrl="admin/status_list.php?problem_id=".$id."&user_id=".$_SESSION['user_id'];
            $statusListUrl="admin/status_list.php?problem_id=".$id;
        ?>
            <div class="jumbotron col-md-3">
                <h5 class="zz_side_title">题目管理</h5>
                <ul class="zz_side_bar">
                    <li class='zz_first_side_item'>
                        <a href="admin/problem_edit.php?id=<?php echo $id?>&getkey=<?php echo $_SESSION['getkey']?>" >
                            类别: <?php echo $row['source']?>
                        </a>
                    </li>
                    <li class="zz_side_item">
                        [<a href="admin/problem_edit.php?id=<?php echo $id?>&getkey=<?php echo $_SESSION['getkey']?>" >编辑</a>]
                        [<a href='javascript:phpfm(<?php echo $row['problem_id'];?>)'>测试数据</a>]
                        <?php echo $view_df_change; ?>
                        [<a href=<?php echo $statusListUrl?>>状态</a>]
                    </li>
                </ul>
            </div>
        <?php
        }
        ?>
        <div class="jumbotron col-md-3">
            <h5 class="zz_side_title">推荐题目</h5>

            <ul class="zz_side_bar">
                <li class ="zz_first_side_item">
                    <a href='problemset.php?search=<?php echo $row['source']?>'>
                        <button class="btn btn-primary">更多同类题目</button>
                    </a>
                </li>
                <li class='zz_side_item'>
                    <span style="color:#3679b3;">标签:</span>
                    [<a href='problemset.php?search=<?php echo $problem_type?>'>
                        <?php echo $problem_type?>
                    </a>]
                    <?php
                    for($i=0; $i < count($problem_labes); $i++ ) {
                        echo "[<a href='problemset.php?search=".$problem_labes[$i]."'>".$problem_labes[$i]."</a>]";
                    }
                    ?>
                </li>
            </ul>
        </div>
        <!--题解和参考代码侧边栏-->
        <div class="jumbotron col-md-3">
            <h5 class="zz_side_title">题解</h5>
            <ul class="zz_side_bar">
                <li class="zz_side_item">
                    <?php
                    $allowAccess = isset($_SESSION['administrator']);
                    $allowAccess |= isset($_SESSION['teacher']);
                    $allowAccess |= isset($_SESSION['viewcode_no_ac']);
                    if( $allowAccess ) { ?>
                        <a href="status.php?problem_id=<?php echo $id ?>&user_id=<?php echo $row['creater_id'] ?>&language=-1">
                            <button class="btn btn-primary">参考代码</button>
                        </a>
                    <?php } ?>
                    <a href="status.php?problem_id=<?php echo $id ?>&user_id=<?php echo $_SESSION['user_id']; ?>&language=-1">
                        <button class="btn btn-primary">我的提交</button>
                    </a>
                </li>
            </ul>
        </div>
        <div class="jumbotron col-md-12 hidden-xs" style="height: 4rem;">
            <?php
            // 时间限制和内存限制
            echo "<center><div style='margin-top: 1rem;'";
            echo "<span>$MSG_Time_Limit: </span>".$row['time_limit']." 秒&nbsp;&nbsp;";
            echo "<span>$MSG_Memory_Limit: </span>".$row['memory_limit']." MB";

            // 提交和通过次数统计
            echo "&nbsp;&nbsp;<span>$MSG_SUBMIT: </span>".$row['submit']."&nbsp;&nbsp;";
            echo "<span>$MSG_SOVLED: </span>".$row['accepted']."&nbsp;&nbsp;&nbsp;&nbsp;";

            // 提交按钮
            echo "[<a href='submitpage.php?id=$id'>$MSG_SUBMIT</a>]";

            // 状态按钮
            echo "[<a href='problemstatus.php?id=".$row['problem_id']."'>$MSG_STATUS</a>]";

            $allowAccess = isset($_SESSION['administrator']);
            $allowAccess |= isset($_SESSION['problem_editor']) && (strtolower($row['creater_id']) == strtolower($_SESSION['user_id']));

            if( $allowAccess ){
                require_once("include/set_get_key.php");
            ?>
                [<a href="admin/problem_edit.php?id=<?php echo $id?>&getkey=<?php echo $_SESSION['getkey']?>" >编辑</a>]
                [<a href='javascript:phpfm(<?php echo $row['problem_id'];?>)'>测试数据</a>]
            <?php
                echo $view_df_change;
            }
            echo "</div></center>";
            ?>
        </div>
    </div> <!-- /container -->
    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <?php include("template/$OJ_TEMPLATE/js.php");?>
    <script>
        function phpfm(pid){
            $.post("admin/phpfm.php",{'frame':3,'pid':pid,'pass':''},function(data,status){
                if(status=="success"){
                    document.location.href="admin/phpfm.php?frame=3&pid="+pid;
                }
            });
        }

        $(document).ready(function() {
            //$("#creator").load("problem-ajax.php?pid=<?php echo $id?>");
            $('#sampleinput_btn').click(function () {
                var text=document.getElementById("sampleinput_data").innerText
                var elemCopy = document.createElement('textarea')
                elemCopy.value = text
                document.body.appendChild(elemCopy)
                // 选择对象
                elemCopy.select()
                // 执行浏览器复制命令
                document.execCommand("copy")
                document.body.removeChild(elemCopy)
                $('#sampleinput_btn').text('复制成功')
                setTimeout(function () {
                    $('#sampleinput_btn').text('点此复制')
                }, 200)
            })

            $('#sampleoutput_btn').click(function () {
                var text=document.getElementById("sampleoutput_data").innerText
                var elemCopy = document.createElement('textarea')
                elemCopy.value = text
                document.body.appendChild(elemCopy)
                // 选择对象
                elemCopy.select()
                // 执行浏览器复制命令
                document.execCommand("Copy")
                document.body.removeChild(elemCopy)
                $('#sampleoutput_btn').text('复制成功')
                setTimeout(function () {
                    $('#sampleoutput_btn').text('点此复制')
                }, 200)
            })
        });
    </script>
</body>
</html>